﻿@namespace Masa.Blazor
@using StyleBuilder = Masa.Blazor.Core.StyleBuilder
@inherits MasaComponentBase

<CascadingValue Value="IsDark" Name="IsDark">
    <CascadingValue Value="this" IsFixed>
        <div class="@GetClass()"
             style="@GetStyle()"
             id="@Id"
             @attributes="@Attributes"
             @ref="Ref">
            <MTabsBar Mandatory="@(!Optional)"
                      NextIcon="@NextIcon"
                      PrevIcon="@PrevIcon"
                      ShowArrows="@ShowArrows"
                      Value="@Value"
                      ValueChanged="@OnValueChanged"
                      Color="@Color"
                      ActiveClass="@ActiveClass"
                      CenterActive="@CenterActive"
                      BackgroundColor="@BackgroundColor"
                      Dark="@Dark"
                      Light="@Light"
                      Style="@(StyleBuilder.Create().AddHeight(Height).Build())"
                      @ref="TabsBarRef">
                @if (!HideSlider)
                {
                    @GenSlider()
                }

                @ChildContent
            </MTabsBar>

            @if (TabItems.Any())
            {
                <MWindow Value="Value">
                    @foreach (var tabItem in TabItems)
                    {
                        <MWindowItem Value="@tabItem.Value"
                                     ActiveClass="@tabItem.ActiveClass"
                                     Disabled="@tabItem.Disabled"
                                     Class="@tabItem.Class"
                                     Style="@tabItem.Style"
                                     Transition="@tabItem.Transition"
                                     ReverseTransition="@tabItem.ReverseTransition">
                            @tabItem.ChildContent
                        </MWindowItem>
                    }
                </MWindow>
            }
        </div>
    </CascadingValue>
</CascadingValue>

@code {

    private RenderFragment GenSlider() => __builder =>
    {
        <div class="m-tabs-slider-wrapper"
             @ref="@_sliderWrapperRef">
            <div class="@GetClass("m-tabs-slider", CssClassUtils.GetBackgroundColor(SliderColor))"
                 style="@(StyleBuilder.Create().AddBackgroundColor(SliderColor))">
            </div>
        </div>
    };

}